<template>
    <div class="mui-numbox"
         data-numbox-min='1'
         :data-numbox-max="$store.getters.getGoodsMax[goodsid]"
         style="height: 26px">
        <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
        <input id="test"
               class="mui-input-numbox"
               type="number" :value="count" ref="numbox"
               @change="countChanged"/>
        <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
</template>

<script>
    import mui from '../../../lib/mui/js/mui.js'

    export default {
        name: "",
        props: ['count', 'goodsid'], //接收商品id和要展示的数量
        data(){
            return {

            }
        },
        mounted(){
            // 初始化数字选择框组件
            mui('.mui-numbox').numbox()
            console.log(this.goodsid);
        },
        beforeUpdate(){
            // console.log(123);
        },
        methods: {
            countChanged(){
                this.$store.commit('updateGoodsCount', { //将商品id和最新改变的数量传递
                    id: this.goodsid,
                    count: parseInt(this.$refs.numbox.value)
                })
            }
        }
    }
</script>

<style scoped>

</style>